#include<stdio.h>
#include<algorithm>
#include<queue> 
using namespace std;
priority_queue<int,vector<int>,greater<int> > q;
const int maxn=1e5+10;
int main()
{
	int n,k;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&k);
		q.push(k);
	}
	int x,y,sum=0;
	while(q.size()>1){
		x=q.top();
		q.pop();
		y=q.top();
		q.pop();
		q.push(x+y);
		sum+=(x+y);
	}
	printf("%d",sum);
	return 0;
}
